package com.drinkdelivery.front.config;

import com.google.common.base.Predicate;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;

/**
 * Swagger配置组件
 */
@Configuration
public class SwaggerConfig {

    //是否开启swagger，正式环境一般是需要关闭的，可根据springboot的多环境配置进行设置
    Boolean swaggerEnabled = true;


    @Bean
    public Docket create1RestApis() {
        return new Docket(DocumentationType.SWAGGER_2)
                .groupName("front")
                .apiInfo(apiInfo())
                // 是否开启
                .enable(swaggerEnabled)
                .select()
                // 扫描的路径包
                .apis(RequestHandlerSelectors.basePackage("com.drinkdelivery.front"))
                // 指定路径处理PathSelectors.any()代表所有的路径
                .paths(frontPathsAnt()) //只监听
                .build()
//                .globalOperationParameters(pars) // 针对单个url的验证 如果需要的话
                .pathMapping("/");
    }


    private Predicate<String> frontPathsAnt() {
        return PathSelectors.ant("/front/**");
    }



    private ApiInfo apiInfo() {
        Contact contact = new Contact("wenle","https://www", "wenle@163.com");
        return new ApiInfoBuilder()
                .title("送酒跑腿小程序接口文档")
                .description("Java送酒跑腿小程序接口文档")
                .contact(contact)
                .termsOfServiceUrl("https://")
                .version("3.8.8").build();
    }


}
